package arthas;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.Charset;

public class test {
    public static void main(String[] args) throws IOException {
        //ps -ef |grep java
        //获取 环境对象
        Runtime runtime = Runtime.getRuntime();
        //设置需要执行的命令
        String command = "ps -ef |grep java";
        String temp = null;
        StringBuilder sb = new StringBuilder();
        //Process运行外部程序
        Process process = runtime.exec(command);
        //IO流读取返回结果
        BufferedReader bufferedReader = new BufferedReader(
                new InputStreamReader(process.getInputStream(), Charset.forName("gbk") ));

        while ((temp = bufferedReader.readLine()) != null) {
            sb.append(temp + "\n");
        }
        //打印结果
        System.out.println(sb.toString());
    }
}
